<html>
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8' >
<link rel="stylesheet" href="../web/styl.css" /> 
<script src='../js/prototype.js' ></script>
<script src='../js/datadumper.js' /></script>
<script src='../js/kato.js' ></script>
</head>
<body onload='Kato.Init({BaseUrl:".."}); mark_row()' onkeyup='obsluga_klawiszy(event)'>
<h1>Wprowadzanie testu</h1>
<script>
var marked_row = 0;
var marked_row_limit = 20

function mark_row(){
	var rows = $('kwadraciki').getElementsByTagName('tr')
	for(var v=1; v < rows.length; v++){
		if((v-1)==marked_row){
			rows[v].style.backgroundColor = '#EEE'
		} else {
			rows[v].style.backgroundColor = ''			
		}
	}

}

function obsluga_klawiszy(event){
	switch(event.keyCode){
		case Event.KEY_DOWN:
			if(marked_row<marked_row_limit-1){
				marked_row++
			}
			break;
		case Event.KEY_UP:
			if(marked_row>0){
				marked_row--
			}
			break;		
		case Event.KEY_RIGHT:
			Kato.Active.kwadraciki.page_flip_next()
			marked_row = 0;
			$('save_kwadraciki').disabled = 'disabled'
			break;		
		case Event.KEY_LEFT:
			Kato.Active.kwadraciki.page_flip_previous()
			marked_row = marked_row_limit - 1
			$('save_kwadraciki').disabled = 'disabled'
			break;
		case Event.KEY_RETURN:
			Kato.Active.kwadraciki.send_data();
			$('save_kwadraciki').disabled = 'disabled'
		default:
			if(event.which>=49 && event.which <=56){
				wybrany_kwadracik('kwadraciki',marked_row,3,new String(event.which-48))
				if(marked_row<marked_row_limit-1){
					marked_row++
				}
			}
			break;
	}
	mark_row()
}

function kwadraciki(row,index,id,row_index){
	var o = '';
	o += '<td>'
	var style = ''
	for(var v=1; v <= 8; v++){
		if(row[index]==v){
			style = v<5 ? 'background-color: green' : 'background-color: red'
		} else {
			style = ""
		}
		if(v==5){
			o += '<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'
		}
		o += '<span style="' + style + '" onclick="wybrany_kwadracik(\'' + id + '\',' + row_index + ',' + index + ',\'' + v + '\')">O</span>'
	}
	o += '</td>'
	return o
}

function wybrany_kwadracik(id,row_index,index,numer_reakcji){
	if(Kato.Active[id].rows[row_index][index]==numer_reakcji)numer_reakcji=''
	Kato.Active[id].set_cell(row_index,index,numer_reakcji)
	Kato.Active[id].build_html();
	Kato.Active[id].element.innerHTML = Kato.Active[id].built_html
	$('save_kwadraciki').disabled = ''
}

</script>
<div
	id='kwadraciki'
	kato_type="Kato.Grid"
	kato_model="wyniki_testow_v"
	kato_server_params="'search_id_testu','orderby_kolejnosc_produktu'"
	kato_params_template="limit:20,search_id_testu:Kato.Request.id_testu, orderby_kolejnosc_produktu:''"
	kato_custom_cell_renderers="id_typu_reakcji:kwadraciki"
	kato_visible_columns="'id_typu_reakcji','nazwa_produktu'"
>
</div>
<input id='save_kwadraciki' type='button' value='zapisz zmiany' disabled='disabled' onclick='Kato.Active.kwadraciki.send_data(); this.disabled="disabled"'>
</body>
</html>